package com.anxin.converter;

import com.anxin.entity.Department;
import com.anxin.entity.excel.DepartmentExcel;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class DepartmentConverter {
    
    public DepartmentExcel toExcel(Department department) {
        if (department == null) {
            return null;
        }
        
        DepartmentExcel excel = new DepartmentExcel();
        excel.setId(department.getId());
        excel.setDepartmentName(department.getDepartmentName());
        excel.setDepartmentCode(department.getDepartmentCode());
        excel.setParentId(department.getParentId());
        excel.setLeader(department.getLeader());
        excel.setPhone(department.getPhone());
        excel.setAddress(department.getAddress());
        excel.setStatus(department.getStatus() == 1 ? "正常" : "停用");
        excel.setRemark(department.getRemark());
        
        return excel;
    }
    
    public Department toEntity(DepartmentExcel excel) {
        if (excel == null) {
            return null;
        }
        
        Department department = new Department();
        department.setId(excel.getId());
        department.setDepartmentName(excel.getDepartmentName());
        department.setDepartmentCode(excel.getDepartmentCode());
        department.setParentId(excel.getParentId());
        department.setLeader(excel.getLeader());
        department.setPhone(excel.getPhone());
        department.setAddress(excel.getAddress());
        department.setStatus("正常".equals(excel.getStatus()) ? 1 : 0);
        department.setRemark(excel.getRemark());
        
        return department;
    }
    
    public List<DepartmentExcel> toExcelList(List<Department> departmentList) {
        return departmentList.stream()
                .map(this::toExcel)
                .collect(Collectors.toList());
    }
    
    public List<Department> toEntityList(List<DepartmentExcel> excelList) {
        return excelList.stream()
                .map(this::toEntity)
                .collect(Collectors.toList());
    }
} 